<?php


namespace app\admin\validate;

use think\Db;
use think\Validate;

class AdForm extends Validate
{
    protected $rule = [

        'type_id|类型'  =>  'require|number|max:11',
        'url|文件' =>  'require|max:200',
        'is_show|是否显示' =>  'require|number',
    ];
    public function add($array){
        $new  = [
            'url'=>$array['url'],
            'title'=>isset($array['title'])?$array['title']:"",
            'link'=>isset($array['link'])?$array['link']:"#",
            'type_id'=>isset($array['type_id'])?$array['type_id']:1,
            'is_show'=>$array['is_show'],
            'create_time'=>date("Y-m-d H:i:s")
        ];
      return checkRes(Db::name('ad')->insert($new),'添加 ');
    }
    public function edit($array){
        $new  = [
            'url'=>$array['url'],
            'title'=>isset($array['title'])?$array['title']:"",
            'link'=>isset($array['link'])?$array['link']:"#",
            'type_id'=>isset($array['type_id'])?$array['type_id']:1,
            'is_show'=>$array['is_show'],
            'create_time'=>date("Y-m-d H:i:s")
        ];
        if(!isset($array['id'])){
            return package(2003,'id错误');
        }
        return checkRes(Db::name('ad')->where('id',$array['id'])->update($new),'修改 ');
    }

}